﻿@{
    ViewBag.Title = "国寿预约管理";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<style type="text/css">
    .layout-split-west {
        border-right-color: Window;
    }
</style>

<div class="easyui-layout" data-options="fit:true" scroll="no">
    <div data-options="region:'west',split:true,title:'机构',iconCls: 'icon-org'" style="width:210px">
        <ul id="tgOrg"></ul>
    </div>
    <div data-options="region:'center',noheader:true,border:false">
        <table id="dgGuoAppointment"></table>
    </div>
</div>
<div id="tbar">
    <div class="tbar">
        <div class="z-toolbar">
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-arrow_refresh',plain:true" onclick="ToolbarRefresh();">刷新</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="ToolbarAdd();">增加</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="ToolbarEdit();">编辑</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cross',plain:true" onclick="ToolbarRemove();">删除</a>
            <div class="datagrid-btn-separator"></div>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="ToolbarUnselect();">取消选中</a>
        </div>
        <form id="searchForm">
            <table>
                <tr>
                    <td>姓名:</td>
                    <td class="td-left"><input type="text" name="GAOName" class="easyui-textbox" /></td>
                    <td class="td-right">卡号:</td>
                    <td class="td-left"><input type="text" name="GAOCardId" class="easyui-textbox" /></td>
                    <td class="td-right">电话:</td>
                    <td class="td-left"><input type="text" name="GAOContactTel" class="easyui-textbox" /></td>
                    <td class="td-right"><a id="btnSearch" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="btnSearch_OnClick()">查询</a></td>
                    <td class="td-right"><a id="btnSearch" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-undo'" onclick="cancelSearch()">取消</a></td>
                </tr>
            </table>
        </form>
    </div>
</div>
@section PageSpecificScript{
    <script type="text/javascript">
        var dgGuoAppointment;/*预约管理*/
        var searchForm;
        $(document).ready(function () {
            searchForm = $("#searchForm");
            $.validateUrl("/Admin/UO_Organization/GetTreeOrgInfo", function () {
                deptTree = $("#tgOrg").tree({
                    url: '/Admin/UO_Organization/GetTreeOrgInfo',
                    onLoadSuccess: function (node, data) {
                        if (data.Msg) {
                            xz.dealWith(data);
                        }
                    },
                    onClick: function (node) {
                        dgGuoAppointment.datagrid('load', {
                            OrgCode: node.id
                        });
                    },
                    onDblClick: function (node) {
                        if (node.state = "closed") {
                            $(this).tree("expand", node.target);
                        } else {
                            $(this).tree("collapse", node.target);
                        }
                    }
                });
                loadGrid();
            });
        }, xz.dealWith, 'GET');
        /*加载datagrid*/
        function loadGrid() {
            dgGuoAppointment = $("#dgGuoAppointment").datagrid({
                url: '/Admin/PE_GuoshouAppointOrder/GetGuoAppointByCondition',
                method: 'Get',
                idField: 'AOOrderId',
                fit: true,
                fitColumns: true,
                rownumbers: true,
                striped: true,
                pagination: true,
                singleSelect: true,
                toolbar: '#tbar',
                pageSize: 20,
                pageList: [20, 30, 40, 50],
                columns: [[
                    { field: 'GAOOrderId', title: '订单编号', width: 100, halign: 'center', align: 'center' },
                    { field: 'GAOThirdOrderId', title: '预约编号', width: 80, halign: 'center', align: 'center' },
                    { field: 'GAOName', title: '客户姓名', width: 80, halign: 'center', align: 'center' },
                    { field: 'GAOIdNumber', title: '身份证号', width: 80, halign: 'center', align: 'center' },
                    { field: 'GAOContactTel', title: '联系方式', width: 80, halign: 'center', align: 'center' },
                    {
                        field: 'GAOSex', title: '性别', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                            if (value == 1) {
                                return xz.fs('<span class="icon-boy" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span>男');
                            } else {
                                return xz.fs('<span class="icon-girl" style="display:inline-block;vertical-align:middle;width:16px;height:16px;"></span>女');
                            }
                        }
                    },
                    {
                        field: 'GAOMarried', title: '婚姻', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                            if (value == 1) {
                                return "已婚";
                            } else {
                                return "未婚";
                            }
                        }
                    },
                    { field: 'GAOCardId', title: '卡号', width: 80, halign: 'center', align: 'center' },
                    { field: 'GAOHospName', title: '体检机构', width: 80, halign: 'center', align: 'center' },
                    { field: 'GAOPackageName', title: '套餐名称', width: 80, halign: 'center', align: 'center' },
                    {
                        field: 'GAORegDate', title: '体检日期', width: 80, halign: 'center', align: 'center', formatter: function (value, row, index) {
                            if (value) {
                                return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
                            }
                        }
                    },
                    {
                        field: 'GAOCreateDate', title: '预约日期', width: 80, halign: 'center', align: 'center', formatter: function (value, row, index) {
                            if (value) {
                                return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString();
                            }
                        }
                    },
                    {
                        field: 'GAOIsdelete', title: '状态', width: 60, halign: 'center', align: 'center', formatter: function (value, row, index) {
                            if (value == 1) {
                                return "已取消";
                            } else {
                                return "已预约";
                            }
                        }
                    }
                ]],
                onDblClickRow: function (rowIndex, rowData) {
                    if (editRow != undefined) {
                        dgGuoAppointment.datagrid('endEdit', editRow);
                    } else {
                        dgGuoAppointment.datagrid('beginEdit', rowIndex);
                        editUser = rowIndex;
                        dgGuoAppointment.datagrid('selectRow', editUser);
                    }
                },
                onRowContextMenu: function (e, rowIndex, rowData) {
                    e.preventDefault();
                    $(this).datagrid("unselectAll");
                    $(this).datagrid("selectRow", rowIndex);
                    $("#menu").menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }
            });
        }
        /*过滤用户信息*/
        function btnSearch_OnClick() {
            dgGuoAppointment.datagrid('load', xz.serializeObject(searchForm));
        }
        /*取消过滤用户信息*/
        function cancelSearch() {
            searchForm.form('clear');
            dgGuoAppointment.datagrid('load', {});
        }
        /**刷新菜单**/
        function ToolbarRefresh() {
            dgGuoAppointment.datagrid("load");
        }
        /**增加菜单**/
        function ToolbarAdd() {
            showAppendView();
        }
        /**设置用户角色**/
        function ToolbarSetRole() {
            showSetRoleView();
        }
        /**设置用户部门**/
        function ToolbarSetDept() {
            showSetDeptView();
        }
        /**编辑菜单**/
        function ToolbarEdit() {
            showEditView();
        }
        /**删除菜单**/
        function ToolbarRemove() {
            removeAppointment();
        }
        /**取消选中菜单**/
        function ToolbarUnselect() {
            dgGuoAppointment.datagrid("unselectAll");
        }
        /*打开添加权限信息的页面*/
        function showAppendView() {
            $.validateUrl('/Admin/PE_Appointment/EditView', append, xz.dealWith, 'GET');
        }
        /*增加用户信息*/
        function append() {
            var pAdd = xz.dialog({
                title: '新增用户',
                width: 680,
                height: 450,
                iconCls: 'icon-add',
                href: '/Admin/PE_Appointment/EditView',
                buttons: [{
                    text: '新增',
                    iconCls: 'icon-add',
                    handler: function () {
                        var f = pAdd.find('form');
                        f.form('submit', {
                            url: '/Admin/PE_Appointment/AddAppointment',
                            onSubmit: function () {
                                return true;
                            },
                            success: function (jsonData) {
                                jsonData = $.parseJSON(jsonData);
                                $.procAjaxMsg(jsonData, function () {
                                    pAdd.dialog('close');
                                    dgGuoAppointment.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        pAdd.dialog('close');
                    }
                }],
                onLoad: function () {
                    var f = pAdd.find('form');
                    var uName = f.find('input[name=UName]');
                    var uOrganization = f.find('input[name=UOrganization]');
                    var uProFessTitle = f.find('input[name=UProFessTitle]');

                    window.setTimeout(function () {
                        uName.focus();
                    }, 100);
                }
            })
        }
        /*设置用户部门*/
        function showSetDeptView() {
            $.validateUrl('/Admin/PE_Appointment/SetAppointmentDepartmentView', SetAppointmentDepartment, xz.dealWith, 'Get');
        }
        /*设置用户部门*/
        function SetAppointmentDepartment() {
            var node = dgGuoAppointment.datagrid("getSelected");
            var dgDepartment;
            if (node) {
                var pAdd = xz.dialog({
                    title: '设置用户部门',
                    width: 600,
                    height: 180,
                    iconCls: 'icon-depset',
                    href: '/Admin/PE_Appointment/SetAppointmentDepartmentView',
                    buttons: [{
                        text: '设置',
                        iconCls: 'icon-depset',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit', {
                                url: '/Admin/PE_Appointment/SetAppointmentDepartment',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgGuoAppointment.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var uId = f.find('input[name=UId]');
                        var uName = f.find('input[name=UName]');
                        var depIds = f.find('input[name=DepIds]');

                        window.setTimeout(function () {
                            uName.focus();
                        }, 100);

                        depIds.combotree({
                            url: '/Admin/UO_Department/GetDeptTree',
                            method: 'GET',
                            lines: true,
                            multiple: true,
                            cascadeCheck: false,
                            valueField: 'id',
                            textField: 'text',
                            editable: false
                        });

                        /*把选中的组织机构信息绑定到对应的表单上*/
                        f.form('load', {
                            UId: node.UId,
                            UName: node.UName,
                            DepIds: xz.getList(node.DepIds)
                        });
                    }
                })
            } else {
                xz.messageAlert("提示", "请选择要设置的用户", "error", null);
            }
        }
        /*设置用户角色*/
        function showSetRoleView() {
            $.validateUrl('/Admin/PE_Appointment/SetAppointmentRoleView', SetAppointmentRole, xz.dealWith, 'Get');
        }
        /*修改用户角色*/
        function SetAppointmentRole() {
            var node = dgGuoAppointment.datagrid("getSelected");
            var dgDepartment;
            if (node) {
                var pAdd = xz.dialog({
                    title: '设置用户角色',
                    width: 600,
                    height: 180,
                    iconCls: 'icon-roleset',
                    href: '/Admin/PE_Appointment/SetAppointmentRoleView',
                    buttons: [{
                        text: '设置',
                        iconCls: 'icon-roleset',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit', {
                                url: '/Admin/PE_Appointment/SetAppointmentRole',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgGuoAppointment.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var uId = f.find('input[name=UId]');
                        var uName = f.find('input[name=UName]');
                        var rId = f.find('input[name=RId]');

                        window.setTimeout(function () {
                            uName.focus();
                        }, 100);

                        rId.combobox({
                            url: '/Admin/UO_Role/GetRoleCombox',
                            method: 'GET'
                        });

                        /*把选中的组织机构信息绑定到对应的表单上*/
                        f.form('load', node);
                    }
                })
            } else {
                xz.messageAlert("提示", "请选择要设置的用户", "error");
            }
        }
        /*编辑用户信息*/
        function showEditView() {
            $.validateUrl('/Admin/PE_Appointment/EditView', edit, xz.dealWith, 'Get');
        }
        /*编辑用户信息*/
        function edit() {
            var node = dgGuoAppointment.datagrid("getSelected");
            var dgDepartment;
            if (node) {
                var pAdd = xz.dialog({
                    title: '修改用户',
                    width: 680,
                    height: 450,
                    iconCls: 'icon-edit',
                    href: '/Admin/PE_Appointment/EditView',
                    buttons: [{
                        text: '修改',
                        iconCls: 'icon-edit',
                        handler: function () {
                            var f = pAdd.find('form');
                            f.form('submit',{
                                url: '/Admin/PE_Appointment/EditAppointment',
                                success: function (jsonData) {
                                    jsonData = $.parseJSON(jsonData);
                                    $.procAjaxMsg(jsonData, function () {
                                        pAdd.dialog('close');
                                        dgGuoAppointment.datagrid("reload");
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    }, function () {
                                        $.alertMsg(jsonData.Msg, "操作提示", null);
                                    });
                                }
                            });
                        }
                    }, {
                        text: '关闭',
                        iconCls: 'icon-cancel',
                        handler: function () {
                            pAdd.dialog('close');
                        }
                    }],
                    onLoad: function () {
                        var f = pAdd.find('form');
                        var uName = f.find('input[name=UName]');
                        var uNation = f.find('input[name=UNation]');
                        var uEducation = f.find('input[name=UEducation]');
                        var uDegree = f.find('input[name=UDegree]');
                        var uProFessTitle = f.find('input[name=UProFessTitle]');

                        window.setTimeout(function () {
                            uName.focus();
                        }, 100);

                        uNation.combobox({
                            url: '/Admin/Sys_Dict/GetDictValueByKey?keyId=5',
                            method: 'GET'
                        });

                        uEducation.combobox({
                            url: '/Admin/Sys_Dict/GetDictValueByKey?keyId=1',
                            method: 'GET'
                        });

                        uProFessTitle.combobox({
                            url: '/Admin/Sys_Dict/GetDictValueByKey?keyId=7',
                            method: 'GET'
                        });

                        uDegree.combobox({
                            url: '/Admin/Sys_Dict/GetDictValueByKey?keyId=2',
                            method: 'GET'
                        });


                        /*把选中的组织机构信息绑定到对应的表单上*/
                        f.form('load', node);
                    }
                })
            } else {
                xz.messageAlert("提示", "请选择要修改的用户", "error");
            }
        }

        /*删除用户*/
        function removeAppointment() {
            var rows = dgGuoAppointment.datagrid("getSelected");
            if (rows) {
                xz.messageConfirm('询问', '你确定要删除【' + rows.UName + '】吗?', function (b) {
                    if (b) {
                        $.ajax({
                            type: 'POST',
                            url: '/Admin/PE_Appointment/DelAppointment',
                            data: {
                                UId: rows.UId
                            },
                            cache: false,
                            dataType: 'JSON',
                            success: function (jsonData) {
                                $.procAjaxMsg(jsonData, function () {
                                    dgGuoAppointment.datagrid("reload");
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                }, function () {
                                    $.alertMsg(jsonData.Msg, "操作提示", null);
                                });
                            }
                        });
                    }
                });
            } else {
                xz.messageAlert("提示", "请选择要删除的用户", "error");
            }
        }


        //选择上级节点
        function selectParent(pid) {
            $("[name=OrgID]:checkbox").each(function () {
                if (pid > 0) {
                    var checked = $(this).attr("checked");
                    $("[name=OrgID]:checkbox").each(function () {
                        if (pid == $(this).val() && checked == "checked") {
                            $(this).attr("checked", "checked");
                            selectParent($(this).parent().parent().parent().siblings().eq(0).find("div").text());
                            return false;
                        }
                    })
                }
            })
        }
        //选择下级节点
        function selectChildren(modID, checked) {
            $("[name=OrgID]:checkbox").each(function () {
                var parentID = $(this).parent().parent().parent().siblings().eq(0).find("div").text();
                if (modID == parentID) {
                    if (checked != "checked") {
                        $(this).removeAttr("checked");
                    }
                    selectChildren($(this).val(), $(this).attr("checked"));
                }
            })
        }
    </script>
}
